package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.business.api.domain.StrategyRank;
import cn.wolfcode.wolf2w.business.query.StrategyRankQuery;
import cn.wolfcode.wolf2w.business.service.IStrategyRankService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Random;

/**
 * 攻略排行 Controller
 * 
 * @author fang
 * @date 2024-09-27
 */
@RestController
//修饰类
@Api(value = "攻略排行榜接口" ,tags = "旅游攻略排行榜接口控制器")
@RequestMapping("strategyRanks")

public class StrategyRankController {
    @Autowired
    private IStrategyRankService strategyRankService;
    /**
     * 攻略排行详情
     */
    @GetMapping("/detail/{id}")
    public R<StrategyRank> detail(@PathVariable Long id) {
        StrategyRank strategyRank = strategyRankService.getById(id);
        return R.ok(strategyRank);
    }
    /**
     * 攻略排行 列表
     */
    @GetMapping("/query")
    public R<IPage<StrategyRank>> query(StrategyRankQuery qo) {
        IPage<StrategyRank> page = strategyRankService.queryPage(qo);
        return R.ok(page);
    }

    @ApiOperation(value = "排行榜查询",notes = "根据分类查询排行榜：热门，国外，国内")
    @ApiImplicitParams(
            @ApiImplicitParam(value = "排行分类",name = "type",dataType = "int",required = true,example = "1")
    )
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 500,message = "系统异常"),
            @ApiResponse(code = 501,message = "业务异常"),
            @ApiResponse(code = 401,message = "未登录"),
            @ApiResponse(code = 403,message = "无权限"),
            @ApiResponse(code = 404,message = "找不到网页")
    })
    @GetMapping("/rank")
    public R<List<StrategyRank>> rank(int type){
        List<StrategyRank> list =  strategyRankService.queryByType(type);
        return R.ok(list);
    }

/*    @GetMapping("/theme")
    public R<List<StrategyRank>> theme(){
        //先获取主题表中所有的主题
        List<StrategyRank> list = strategyRankService.queryThemeList();
        return R.ok(list);
    }*/


    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<StrategyRank>> feignList() {
        return R.ok(strategyRankService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<StrategyRank> feignGet(@PathVariable Long id) {
        return R.ok(strategyRankService.getById(id));
    }

    //需要内部的权限判断，就是内部鉴权
    @GetMapping("/feign/statisRank")
    @InnerAuth
    public R<StrategyRank> statisRank(@RequestHeader(SecurityConstants.FROM_SOURCE) String source){
        //查询结果。
        strategyRankService.statisRank();
        return R.ok();
    }

    @GetMapping("/testRank")
    public R<?> testRank(StrategyRank rank){
        return R.ok();
    }

}
